package com.example.work01.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.work01.entity.Diary;
import com.example.work01.mapper.DiaryMapper;
import com.example.work01.service.DiaryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 日记表 服务实现类
 * </p>
 *
 * @author myb
 * @since 2023-10-01
 */
@Service
public class DiaryServiceImpl extends ServiceImpl<DiaryMapper, Diary> implements DiaryService {

    @Override
    public IPage<Diary> findPage(Integer pageNum, Integer pageSize, Diary diary) {
        Page<Diary> page = new Page<>(pageNum, pageSize);
        QueryWrapper<Diary> wrapper = new QueryWrapper<>();
        wrapper.like(!StringUtils.isEmpty(diary.getTitle()), "title", diary.getTitle())
                .eq(!StringUtils.isEmpty(diary.getTypeid()), "d.typeid", diary.getTypeid());
        return this.baseMapper.findPage(page, wrapper);
    }
}
